import defaultsState from './data'
import {
  CHANGE_IF_NAV,
  CHANGE_LIKE_NAV_INDEX,
  ADD_NUM,
  LESS_NUM,
  SET_EMPTY,
  CHANGE_DISCOUNT_NAV,
  CHANGE_ORDER_NAV,
  CHANGE_CURR_IFICATION_NAV,
  CAHNGE_CURR_EVALUATION_NAV

} from './actionType'
import index from "@tarojs/react";

export default (state = defaultsState, action) => {
  switch (action.type) {
    case CHANGE_IF_NAV:
      let newState = JSON.parse(JSON.stringify(state))
      newState.navListIndex = action.index
      return newState
    case CHANGE_LIKE_NAV_INDEX:
      let newLikeState = JSON.parse(JSON.stringify(state))
      newLikeState.likeNavIndex = action.index
      return newLikeState
    case ADD_NUM:
      let addNum = JSON.parse(JSON.stringify(state))
      addNum.num = action.num
      return addNum
    case LESS_NUM:
      let lessNum = JSON.parse(JSON.stringify(state))
      lessNum.num = action.num
      return lessNum
    case SET_EMPTY:
      let newSearch = JSON.parse(JSON.stringify(state))
      newSearch.searchList = []
      return newSearch
    case CHANGE_DISCOUNT_NAV:
      let newDiscountNav = JSON.parse((JSON.stringify(state)))
      newDiscountNav.currDiscountNav = action.index
      return newDiscountNav
    case CHANGE_ORDER_NAV:
      let newOrderNav = JSON.parse(JSON.stringify(state))
      newOrderNav.currOrderNav = action.index
      return  newOrderNav
    case CHANGE_CURR_IFICATION_NAV:
      let newIficationNav = JSON.parse(JSON.stringify(state))
      newIficationNav.currIficationNav = action.index
      return  newIficationNav
    case CAHNGE_CURR_EVALUATION_NAV:
      let newCurrEvaluationNav = JSON.parse(JSON.stringify(state))
      newCurrEvaluationNav.currEvaluationNav = action.index
      return newCurrEvaluationNav
  }
  return state
}
